#include "tp6817.h"
//#include "osd_func.h"
#include "test_res.h"

#define spi_load_rls(o_addr, n_addr, count, addend)		spi_load_type(o_addr, n_addr, count, addend, LOAD_TYPE_RLs)
void osd_init()
{

}
void osd_wr_en (unsigned char en)
{
	write_p2(OSD_CTRL_REG, en);
}
void osd_wr_rls_en (unsigned char en)
{
	write_p2(RLS_REG_EN_CTRL, (read_p2(RLS_REG_EN_CTRL) & 0x0f) | en);
}

void rls_config(unsigned char offset, unsigned long nor_addr);
#define rls_A_config(addr)	rls_config(0, addr)
#define rls_B_config(addr)	rls_config(1, addr)
#define rls_C_config(addr)	rls_config(2, addr)
#define rls_D_config(addr)	rls_config(3, addr)

uint8_t spi_load_type(unsigned short oram_addr, unsigned long nor_addr, 
                unsigned short count, unsigned long addend, unsigned char type)
{
	short timeout;

    write_p2(OSD_ORAM_PTR_L, (oram_addr & 0xff));
    write_p2(OSD_ORAM_PTR_M, ((oram_addr >> 8) & 0xff));
	switch(type) {
	case LOAD_TYPE_LUT:
		/* When load LUT data, this must be DWord aligned (A[1:0] == 2'b00) */
        write_p2(OSD_ACCESS_TYPE, OSD_ACCESS_LUT);
		break;
	case LOAD_TYPE_FATT:
		/* When load FAtt data, this must be Word aligned (A[0] == 1'b0) */
        write_p2(OSD_ACCESS_TYPE, OSD_BYTE_W_6 | OSD_ACCESS_LUT);
		break;
	case LOAD_TYPE_RLg:
	case LOAD_TYPE_Row:
	case LOAD_TYPE_RLs:
	case LOAD_TYPE_ORAM:
	default:
		/* No Byte/Word/DW alignment when move data from SPI to oRAM */
        write_p2(OSD_ACCESS_TYPE, OSD_ACCESS_ORAM);
		break;
	}
    write_p2(OSD_BASS_PTR_ADDEND_7_0, (addend & 0xff));
    write_p2(OSD_BASS_PTR_ADDEND_15_8, ((addend >> 8) & 0xff));
    write_p2(OSD_BASS_PTR_ADDEND_23_16, ((addend >> 16) & 0xff));
	if(addend > 0) {
		/* Addend_Type[2:0]
		 *  These 3 bits will be reset whenever ORAM_Ptr/FontAtt_Ptr
		 *  being programmed
		 *  */
        write_p2(OSD_BASS_PTR_ADDEND_26_24, ((addend >> 24) & 0x03));
		switch(type) {
		case LOAD_TYPE_FATT:
            write_p2(OSD_BASS_PTR_ADDEND_26_24, 
            (read_p2(OSD_BASS_PTR_ADDEND_26_24) | ADDEND_TYPE_FATT));
			break;
		case LOAD_TYPE_Row:
            write_p2(OSD_BASS_PTR_ADDEND_26_24, 
            (read_p2(OSD_BASS_PTR_ADDEND_26_24) | ADDEND_TYPE_ROWATT));
			break;
		case LOAD_TYPE_RLg:
            write_p2(OSD_BASS_PTR_ADDEND_26_24, 
            (read_p2(OSD_BASS_PTR_ADDEND_26_24) | ADDEND_TYPE_RLGATT));
			break;
		case LOAD_TYPE_RLs:
            write_p2(OSD_BASS_PTR_ADDEND_26_24, 
            (read_p2(OSD_BASS_PTR_ADDEND_26_24) | ADDEND_TYPE_RLSATT));
			break;
		}
	} else {
		write_p2(OSD_BASS_PTR_ADDEND_26_24, ADDEND_TYPE_DISABLE);
	}

#if defined(RES_BUILTIN_CODESPACE)
	if(RBKL0) {
		nor_addr = nor_addr + (unsigned long) (RBKL0 << 14);
	}
#endif

    write_p2(OSD_SPI_ADDRESS_7_0, (nor_addr & 0xff));
    write_p2(OSD_SPI_ADDRESS_15_8, ((nor_addr >> 8) & 0xff));
    write_p2(OSD_SPI_ADDRESS_23_16, ((nor_addr >> 16) & 0xff));
    write_p2(OSD_SPI_ADDRESS_31_24, ((nor_addr >> 24) & 0xff));
    write_p2(OSD_SPI_LOAD_CNT_L, (count & 0xff));
    write_p2(OSD_SPI_LOAD_CNT_H, (OSD_GO_LOAD | ((count >> 8) & 0x3f)));

	timeout = read_cpu_count() + 1000;  // 1s
	while(read_p2(OSD_SPI_LOAD_CNT_H) & OSD_GO_LOAD) {
		// Busy
        if(is_time_outs(timeout)) {
//			DBGMSG(("[ERROR] spi_load timeout!\n"));
			return EXIT_FAILURE;
		}
	}

	return EXIT_SUCCESS;
}
void rls_config(unsigned char offset, unsigned long nor_addr)
{
	unsigned char i = 0;	
	unsigned char buffer[RLS_REG_CONFIG_COUNT];

	if(spi_dma(buffer, nor_addr, RLS_REG_CONFIG_COUNT) != EXIT_SUCCESS) {
		return;
	}	
#if 0
	for(i = 0; i < 8; i++) {
        write_p2((RLS_REG_START_INDEX + offset * 8 + i), buffer[i]);
	}
#endif	
    write_p2(OSD_REG_INDEX, (RLS_OSD_POS_INDEX + offset * 4));
	for(i = 0; i < 4; i++) {
        write_p2(OSD_REG_DATA, (buffer[i]));
	}
    write_p2(OSD_REG_INDEX, (RLS_OSD_PTR_INDEX + offset * 2));
    write_p2(OSD_REG_DATA, (buffer[4]));
	write_p2(OSD_REG_DATA, (buffer[5]));
	// 2 dummy bytes
}


void get_test_res_version(void)
{
#if 0
	unsigned char cnt = 0;
	unsigned char xdata buf[TEST_VERSION_CNT];

	if (spi_dma(buf, TEST_VERSION_CODE_OFFSET, TEST_VERSION_CNT)
		!= EXIT_SUCCESS) {
		DBGMSG(("DMA failed, can't get Resource Header!\n"));
	}
	if (*((unsigned long *)(buf + TEST_HEADER_START_IDX))
		!= TEST_MAGIC_START) {
		DBGMSG(("Header first magic number mismatch!\n"));
	}
	if (*((unsigned long *)(buf + TEST_HEADER_END_IDX))
		!= TEST_MAGIC_END) {
		DBGMSG(("Header last magic number mismatch!\n"));
	}
	/* You can get version number here,
	* probably you want to do something like checking the version. */
	DBGMSG(("TEST Resource ID:%02bX%02bX Version:v%bd.%bd Size:%ld\n",
		buf[TEST_RES_VER_IDX + 0],
		buf[TEST_RES_VER_IDX + 1],
		buf[TEST_RES_VER_IDX + 2],
		buf[TEST_RES_VER_IDX + 3],
		*((unsigned long *)(buf + TEST_RES_SIZE_IDX))));
#endif
}



void show_BackLightMain_page (void)
{
	osd_init();

	spi_load_rls(BackLightMain_com_1_rlsatt_ptr, BackLightMain_com_1_rlsatt_addr,
			BackLightMain_com_1_rlsatt_size, BACKLIGHTMAIN_CODE_OFFSET);

	spi_load_rls(BackLightMain__dummy2__rlsatt_ptr, BackLightMain__dummy2__rlsatt_addr,
			BackLightMain__dummy2__rlsatt_size, BACKLIGHTMAIN_CODE_OFFSET); // dummy


	spi_load_rls(BackLightMain_com_0_rlsatt_ptr, BackLightMain_com_0_rlsatt_addr,
			BackLightMain_com_0_rlsatt_size, BACKLIGHTMAIN_CODE_OFFSET);

	spi_load_rls(BackLightMain__dummy3__rlsatt_ptr, BackLightMain__dummy3__rlsatt_addr,
			BackLightMain__dummy3__rlsatt_size, BACKLIGHTMAIN_CODE_OFFSET); // dummy




	row_A_disable();
	row_B_disable();
	row_C_disable();
	row_D_disable();
	rlg_A_disable();
	rlg_B_disable();
	rlg_C_disable();
	rlg_D_disable();
	rls_C_config(BackLightMain_RLs_Thread_C_regaddr);
	rls_D_config(BackLightMain_RLs_Thread_D_regaddr);
	win_A_disable();
	win_B_disable();
	win_C_disable();
	win_D_disable();
	mat_A_disable();
	mat_B_disable();
	mat_C_disable();
	mat_D_disable();


	osd_wr_rls_en(RLS_D_EN | RLS_C_EN);
	osd_wr_en(OSD_CTRL_EN | OSD_RLS_EN);
}






void show_BackLight_1_page (void)
{
	osd_init();

	spi_load_rls(BackLight_1_com_2_rlsatt_ptr, BackLight_1_com_2_rlsatt_addr,
			BackLight_1_com_2_rlsatt_size, BACKLIGHT_1_CODE_OFFSET);

	spi_load_rls(BackLight_1__dummy1__rlsatt_ptr, BackLight_1__dummy1__rlsatt_addr,
			BackLight_1__dummy1__rlsatt_size, BACKLIGHT_1_CODE_OFFSET); // dummy


	spi_load_rls(BackLight_1_com_1_rlsatt_ptr, BackLight_1_com_1_rlsatt_addr,
			BackLight_1_com_1_rlsatt_size, BACKLIGHT_1_CODE_OFFSET);

	spi_load_rls(BackLight_1__dummy2__rlsatt_ptr, BackLight_1__dummy2__rlsatt_addr,
			BackLight_1__dummy2__rlsatt_size, BACKLIGHT_1_CODE_OFFSET); // dummy


	spi_load_rls(BackLight_1_com_0_rlsatt_ptr, BackLight_1_com_0_rlsatt_addr,
			BackLight_1_com_0_rlsatt_size, BACKLIGHT_1_CODE_OFFSET);

	spi_load_rls(BackLight_1__dummy3__rlsatt_ptr, BackLight_1__dummy3__rlsatt_addr,
			BackLight_1__dummy3__rlsatt_size, BACKLIGHT_1_CODE_OFFSET); // dummy




	row_A_disable();
	row_B_disable();
	row_C_disable();
	row_D_disable();
	rlg_A_disable();
	rlg_B_disable();
	rlg_C_disable();
	rlg_D_disable();
	rls_B_config(BackLight_1_RLs_Thread_B_regaddr);
	rls_C_config(BackLight_1_RLs_Thread_C_regaddr);
	rls_D_config(BackLight_1_RLs_Thread_D_regaddr);
	win_A_disable();
	win_B_disable();
	win_C_disable();
	win_D_disable();
	mat_A_disable();
	mat_B_disable();
	mat_C_disable();
	mat_D_disable();


	osd_wr_rls_en(RLS_D_EN | RLS_C_EN | RLS_B_EN);
	osd_wr_en(OSD_CTRL_EN | OSD_RLS_EN);
}






void show_BackLight_2_page (void)
{
	osd_init();

	spi_load_rls(BackLight_2_com_2_rlsatt_ptr, BackLight_2_com_2_rlsatt_addr,
			BackLight_2_com_2_rlsatt_size, BACKLIGHT_2_CODE_OFFSET);

	spi_load_rls(BackLight_2__dummy1__rlsatt_ptr, BackLight_2__dummy1__rlsatt_addr,
			BackLight_2__dummy1__rlsatt_size, BACKLIGHT_2_CODE_OFFSET); // dummy


	spi_load_rls(BackLight_2_com_1_rlsatt_ptr, BackLight_2_com_1_rlsatt_addr,
			BackLight_2_com_1_rlsatt_size, BACKLIGHT_2_CODE_OFFSET);

	spi_load_rls(BackLight_2__dummy2__rlsatt_ptr, BackLight_2__dummy2__rlsatt_addr,
			BackLight_2__dummy2__rlsatt_size, BACKLIGHT_2_CODE_OFFSET); // dummy


	spi_load_rls(BackLight_2_com_0_rlsatt_ptr, BackLight_2_com_0_rlsatt_addr,
			BackLight_2_com_0_rlsatt_size, BACKLIGHT_2_CODE_OFFSET);

	spi_load_rls(BackLight_2__dummy3__rlsatt_ptr, BackLight_2__dummy3__rlsatt_addr,
			BackLight_2__dummy3__rlsatt_size, BACKLIGHT_2_CODE_OFFSET); // dummy




	row_A_disable();
	row_B_disable();
	row_C_disable();
	row_D_disable();
	rlg_A_disable();
	rlg_B_disable();
	rlg_C_disable();
	rlg_D_disable();
	rls_B_config(BackLight_2_RLs_Thread_B_regaddr);
	rls_C_config(BackLight_2_RLs_Thread_C_regaddr);
	rls_D_config(BackLight_2_RLs_Thread_D_regaddr);
	win_A_disable();
	win_B_disable();
	win_C_disable();
	win_D_disable();
	mat_A_disable();
	mat_B_disable();
	mat_C_disable();
	mat_D_disable();


	osd_wr_rls_en(RLS_D_EN | RLS_C_EN | RLS_B_EN);
	osd_wr_en(OSD_CTRL_EN | OSD_RLS_EN);
}






void show_BackLight_3_page (void)
{
	osd_init();

	spi_load_rls(BackLight_3_com_2_rlsatt_ptr, BackLight_3_com_2_rlsatt_addr,
			BackLight_3_com_2_rlsatt_size, BACKLIGHT_3_CODE_OFFSET);

	spi_load_rls(BackLight_3__dummy1__rlsatt_ptr, BackLight_3__dummy1__rlsatt_addr,
			BackLight_3__dummy1__rlsatt_size, BACKLIGHT_3_CODE_OFFSET); // dummy


	spi_load_rls(BackLight_3_com_1_rlsatt_ptr, BackLight_3_com_1_rlsatt_addr,
			BackLight_3_com_1_rlsatt_size, BACKLIGHT_3_CODE_OFFSET);

	spi_load_rls(BackLight_3__dummy2__rlsatt_ptr, BackLight_3__dummy2__rlsatt_addr,
			BackLight_3__dummy2__rlsatt_size, BACKLIGHT_3_CODE_OFFSET); // dummy


	spi_load_rls(BackLight_3_com_0_rlsatt_ptr, BackLight_3_com_0_rlsatt_addr,
			BackLight_3_com_0_rlsatt_size, BACKLIGHT_3_CODE_OFFSET);

	spi_load_rls(BackLight_3__dummy3__rlsatt_ptr, BackLight_3__dummy3__rlsatt_addr,
			BackLight_3__dummy3__rlsatt_size, BACKLIGHT_3_CODE_OFFSET); // dummy




	row_A_disable();
	row_B_disable();
	row_C_disable();
	row_D_disable();
	rlg_A_disable();
	rlg_B_disable();
	rlg_C_disable();
	rlg_D_disable();
	rls_B_config(BackLight_3_RLs_Thread_B_regaddr);
	rls_C_config(BackLight_3_RLs_Thread_C_regaddr);
	rls_D_config(BackLight_3_RLs_Thread_D_regaddr);
	win_A_disable();
	win_B_disable();
	win_C_disable();
	win_D_disable();
	mat_A_disable();
	mat_B_disable();
	mat_C_disable();
	mat_D_disable();


	osd_wr_rls_en(RLS_D_EN | RLS_C_EN | RLS_B_EN);
	osd_wr_en(OSD_CTRL_EN | OSD_RLS_EN);
}






void show_BackLight_4_page (void)
{
	osd_init();

	spi_load_rls(BackLight_4_com_2_rlsatt_ptr, BackLight_4_com_2_rlsatt_addr,
			BackLight_4_com_2_rlsatt_size, BACKLIGHT_4_CODE_OFFSET);

	spi_load_rls(BackLight_4__dummy1__rlsatt_ptr, BackLight_4__dummy1__rlsatt_addr,
			BackLight_4__dummy1__rlsatt_size, BACKLIGHT_4_CODE_OFFSET); // dummy


	spi_load_rls(BackLight_4_com_0_rlsatt_ptr, BackLight_4_com_0_rlsatt_addr,
			BackLight_4_com_0_rlsatt_size, BACKLIGHT_4_CODE_OFFSET);

	spi_load_rls(BackLight_4__dummy2__rlsatt_ptr, BackLight_4__dummy2__rlsatt_addr,
			BackLight_4__dummy2__rlsatt_size, BACKLIGHT_4_CODE_OFFSET); // dummy


	spi_load_rls(BackLight_4_com_1_rlsatt_ptr, BackLight_4_com_1_rlsatt_addr,
			BackLight_4_com_1_rlsatt_size, BACKLIGHT_4_CODE_OFFSET);

	spi_load_rls(BackLight_4__dummy3__rlsatt_ptr, BackLight_4__dummy3__rlsatt_addr,
			BackLight_4__dummy3__rlsatt_size, BACKLIGHT_4_CODE_OFFSET); // dummy




	row_A_disable();
	row_B_disable();
	row_C_disable();
	row_D_disable();
	rlg_A_disable();
	rlg_B_disable();
	rlg_C_disable();
	rlg_D_disable();
	rls_B_config(BackLight_4_RLs_Thread_B_regaddr);
	rls_C_config(BackLight_4_RLs_Thread_C_regaddr);
	rls_D_config(BackLight_4_RLs_Thread_D_regaddr);
	win_A_disable();
	win_B_disable();
	win_C_disable();
	win_D_disable();
	mat_A_disable();
	mat_B_disable();
	mat_C_disable();
	mat_D_disable();


	osd_wr_rls_en(RLS_D_EN | RLS_C_EN | RLS_B_EN);
	osd_wr_en(OSD_CTRL_EN | OSD_RLS_EN);
}






void show_BackLight_5_page (void)
{
	osd_init();

	spi_load_rls(BackLight_5_com_2_rlsatt_ptr, BackLight_5_com_2_rlsatt_addr,
			BackLight_5_com_2_rlsatt_size, BACKLIGHT_5_CODE_OFFSET);

	spi_load_rls(BackLight_5__dummy1__rlsatt_ptr, BackLight_5__dummy1__rlsatt_addr,
			BackLight_5__dummy1__rlsatt_size, BACKLIGHT_5_CODE_OFFSET); // dummy


	spi_load_rls(BackLight_5_com_0_rlsatt_ptr, BackLight_5_com_0_rlsatt_addr,
			BackLight_5_com_0_rlsatt_size, BACKLIGHT_5_CODE_OFFSET);

	spi_load_rls(BackLight_5__dummy2__rlsatt_ptr, BackLight_5__dummy2__rlsatt_addr,
			BackLight_5__dummy2__rlsatt_size, BACKLIGHT_5_CODE_OFFSET); // dummy


	spi_load_rls(BackLight_5_com_1_rlsatt_ptr, BackLight_5_com_1_rlsatt_addr,
			BackLight_5_com_1_rlsatt_size, BACKLIGHT_5_CODE_OFFSET);

	spi_load_rls(BackLight_5__dummy3__rlsatt_ptr, BackLight_5__dummy3__rlsatt_addr,
			BackLight_5__dummy3__rlsatt_size, BACKLIGHT_5_CODE_OFFSET); // dummy




	row_A_disable();
	row_B_disable();
	row_C_disable();
	row_D_disable();
	rlg_A_disable();
	rlg_B_disable();
	rlg_C_disable();
	rlg_D_disable();
	rls_B_config(BackLight_5_RLs_Thread_B_regaddr);
	rls_C_config(BackLight_5_RLs_Thread_C_regaddr);
	rls_D_config(BackLight_5_RLs_Thread_D_regaddr);
	win_A_disable();
	win_B_disable();
	win_C_disable();
	win_D_disable();
	mat_A_disable();
	mat_B_disable();
	mat_C_disable();
	mat_D_disable();


	osd_wr_rls_en(RLS_D_EN | RLS_C_EN | RLS_B_EN);
	osd_wr_en(OSD_CTRL_EN | OSD_RLS_EN);
}






void show_BackLight_6_page (void)
{
	osd_init();

	spi_load_rls(BackLight_6_com_2_rlsatt_ptr, BackLight_6_com_2_rlsatt_addr,
			BackLight_6_com_2_rlsatt_size, BACKLIGHT_6_CODE_OFFSET);

	spi_load_rls(BackLight_6__dummy1__rlsatt_ptr, BackLight_6__dummy1__rlsatt_addr,
			BackLight_6__dummy1__rlsatt_size, BACKLIGHT_6_CODE_OFFSET); // dummy


	spi_load_rls(BackLight_6_com_0_rlsatt_ptr, BackLight_6_com_0_rlsatt_addr,
			BackLight_6_com_0_rlsatt_size, BACKLIGHT_6_CODE_OFFSET);

	spi_load_rls(BackLight_6__dummy2__rlsatt_ptr, BackLight_6__dummy2__rlsatt_addr,
			BackLight_6__dummy2__rlsatt_size, BACKLIGHT_6_CODE_OFFSET); // dummy


	spi_load_rls(BackLight_6_com_1_rlsatt_ptr, BackLight_6_com_1_rlsatt_addr,
			BackLight_6_com_1_rlsatt_size, BACKLIGHT_6_CODE_OFFSET);

	spi_load_rls(BackLight_6__dummy3__rlsatt_ptr, BackLight_6__dummy3__rlsatt_addr,
			BackLight_6__dummy3__rlsatt_size, BACKLIGHT_6_CODE_OFFSET); // dummy




	row_A_disable();
	row_B_disable();
	row_C_disable();
	row_D_disable();
	rlg_A_disable();
	rlg_B_disable();
	rlg_C_disable();
	rlg_D_disable();
	rls_B_config(BackLight_6_RLs_Thread_B_regaddr);
	rls_C_config(BackLight_6_RLs_Thread_C_regaddr);
	rls_D_config(BackLight_6_RLs_Thread_D_regaddr);
	win_A_disable();
	win_B_disable();
	win_C_disable();
	win_D_disable();
	mat_A_disable();
	mat_B_disable();
	mat_C_disable();
	mat_D_disable();


	osd_wr_rls_en(RLS_D_EN | RLS_C_EN | RLS_B_EN);
	osd_wr_en(OSD_CTRL_EN | OSD_RLS_EN);
}






void show_BackLight_7_page (void)
{
	osd_init();

	spi_load_rls(BackLight_7_com_2_rlsatt_ptr, BackLight_7_com_2_rlsatt_addr,
			BackLight_7_com_2_rlsatt_size, BACKLIGHT_7_CODE_OFFSET);

	spi_load_rls(BackLight_7__dummy1__rlsatt_ptr, BackLight_7__dummy1__rlsatt_addr,
			BackLight_7__dummy1__rlsatt_size, BACKLIGHT_7_CODE_OFFSET); // dummy


	spi_load_rls(BackLight_7_com_1_rlsatt_ptr, BackLight_7_com_1_rlsatt_addr,
			BackLight_7_com_1_rlsatt_size, BACKLIGHT_7_CODE_OFFSET);

	spi_load_rls(BackLight_7__dummy2__rlsatt_ptr, BackLight_7__dummy2__rlsatt_addr,
			BackLight_7__dummy2__rlsatt_size, BACKLIGHT_7_CODE_OFFSET); // dummy


	spi_load_rls(BackLight_7_com_0_rlsatt_ptr, BackLight_7_com_0_rlsatt_addr,
			BackLight_7_com_0_rlsatt_size, BACKLIGHT_7_CODE_OFFSET);

	spi_load_rls(BackLight_7__dummy3__rlsatt_ptr, BackLight_7__dummy3__rlsatt_addr,
			BackLight_7__dummy3__rlsatt_size, BACKLIGHT_7_CODE_OFFSET); // dummy




	row_A_disable();
	row_B_disable();
	row_C_disable();
	row_D_disable();
	rlg_A_disable();
	rlg_B_disable();
	rlg_C_disable();
	rlg_D_disable();
	rls_B_config(BackLight_7_RLs_Thread_B_regaddr);
	rls_C_config(BackLight_7_RLs_Thread_C_regaddr);
	rls_D_config(BackLight_7_RLs_Thread_D_regaddr);
	win_A_disable();
	win_B_disable();
	win_C_disable();
	win_D_disable();
	mat_A_disable();
	mat_B_disable();
	mat_C_disable();
	mat_D_disable();


	osd_wr_rls_en(RLS_D_EN | RLS_C_EN | RLS_B_EN);
	osd_wr_en(OSD_CTRL_EN | OSD_RLS_EN);
}






void show_Video_Main_page (void)
{
	osd_init();

	spi_load_rls(Video_Main_com_1_rlsatt_ptr, Video_Main_com_1_rlsatt_addr,
			Video_Main_com_1_rlsatt_size, VIDEO_MAIN_CODE_OFFSET);

	spi_load_rls(Video_Main__dummy2__rlsatt_ptr, Video_Main__dummy2__rlsatt_addr,
			Video_Main__dummy2__rlsatt_size, VIDEO_MAIN_CODE_OFFSET); // dummy


	spi_load_rls(Video_Main_com_0_rlsatt_ptr, Video_Main_com_0_rlsatt_addr,
			Video_Main_com_0_rlsatt_size, VIDEO_MAIN_CODE_OFFSET);

	spi_load_rls(Video_Main__dummy3__rlsatt_ptr, Video_Main__dummy3__rlsatt_addr,
			Video_Main__dummy3__rlsatt_size, VIDEO_MAIN_CODE_OFFSET); // dummy




	row_A_disable();
	row_B_disable();
	row_C_disable();
	row_D_disable();
	rlg_A_disable();
	rlg_B_disable();
	rlg_C_disable();
	rlg_D_disable();
	rls_C_config(Video_Main_RLs_Thread_C_regaddr);
	rls_D_config(Video_Main_RLs_Thread_D_regaddr);
	win_A_disable();
	win_B_disable();
	win_C_disable();
	win_D_disable();
	mat_A_disable();
	mat_B_disable();
	mat_C_disable();
	mat_D_disable();


	osd_wr_rls_en(RLS_D_EN | RLS_C_EN);
	osd_wr_en(OSD_CTRL_EN | OSD_RLS_EN);
}






void show_Video_1_page (void)
{
	osd_init();

	spi_load_rls(Video_1_com_0_rlsatt_ptr, Video_1_com_0_rlsatt_addr,
			Video_1_com_0_rlsatt_size, VIDEO_1_CODE_OFFSET);

	spi_load_rls(Video_1__dummy1__rlsatt_ptr, Video_1__dummy1__rlsatt_addr,
			Video_1__dummy1__rlsatt_size, VIDEO_1_CODE_OFFSET); // dummy


	spi_load_rls(Video_1_com_1_rlsatt_ptr, Video_1_com_1_rlsatt_addr,
			Video_1_com_1_rlsatt_size, VIDEO_1_CODE_OFFSET);

	spi_load_rls(Video_1__dummy2__rlsatt_ptr, Video_1__dummy2__rlsatt_addr,
			Video_1__dummy2__rlsatt_size, VIDEO_1_CODE_OFFSET); // dummy


	spi_load_rls(Video_1_com_2_rlsatt_ptr, Video_1_com_2_rlsatt_addr,
			Video_1_com_2_rlsatt_size, VIDEO_1_CODE_OFFSET);

	spi_load_rls(Video_1__dummy3__rlsatt_ptr, Video_1__dummy3__rlsatt_addr,
			Video_1__dummy3__rlsatt_size, VIDEO_1_CODE_OFFSET); // dummy




	row_A_disable();
	row_B_disable();
	row_C_disable();
	row_D_disable();
	rlg_A_disable();
	rlg_B_disable();
	rlg_C_disable();
	rlg_D_disable();
	rls_B_config(Video_1_RLs_Thread_B_regaddr);
	rls_C_config(Video_1_RLs_Thread_C_regaddr);
	rls_D_config(Video_1_RLs_Thread_D_regaddr);
	win_A_disable();
	win_B_disable();
	win_C_disable();
	win_D_disable();
	mat_A_disable();
	mat_B_disable();
	mat_C_disable();
	mat_D_disable();


	osd_wr_rls_en(RLS_D_EN | RLS_C_EN | RLS_B_EN);
	osd_wr_en(OSD_CTRL_EN | OSD_RLS_EN);
}






void show_Video_2_page (void)
{
	osd_init();

	spi_load_rls(Video_2_com_2_rlsatt_ptr, Video_2_com_2_rlsatt_addr,
			Video_2_com_2_rlsatt_size, VIDEO_2_CODE_OFFSET);

	spi_load_rls(Video_2__dummy1__rlsatt_ptr, Video_2__dummy1__rlsatt_addr,
			Video_2__dummy1__rlsatt_size, VIDEO_2_CODE_OFFSET); // dummy


	spi_load_rls(Video_2_com_1_rlsatt_ptr, Video_2_com_1_rlsatt_addr,
			Video_2_com_1_rlsatt_size, VIDEO_2_CODE_OFFSET);

	spi_load_rls(Video_2__dummy2__rlsatt_ptr, Video_2__dummy2__rlsatt_addr,
			Video_2__dummy2__rlsatt_size, VIDEO_2_CODE_OFFSET); // dummy


	spi_load_rls(Video_2_com_0_rlsatt_ptr, Video_2_com_0_rlsatt_addr,
			Video_2_com_0_rlsatt_size, VIDEO_2_CODE_OFFSET);

	spi_load_rls(Video_2__dummy3__rlsatt_ptr, Video_2__dummy3__rlsatt_addr,
			Video_2__dummy3__rlsatt_size, VIDEO_2_CODE_OFFSET); // dummy




	row_A_disable();
	row_B_disable();
	row_C_disable();
	row_D_disable();
	rlg_A_disable();
	rlg_B_disable();
	rlg_C_disable();
	rlg_D_disable();
	rls_B_config(Video_2_RLs_Thread_B_regaddr);
	rls_C_config(Video_2_RLs_Thread_C_regaddr);
	rls_D_config(Video_2_RLs_Thread_D_regaddr);
	win_A_disable();
	win_B_disable();
	win_C_disable();
	win_D_disable();
	mat_A_disable();
	mat_B_disable();
	mat_C_disable();
	mat_D_disable();


	osd_wr_rls_en(RLS_D_EN | RLS_C_EN | RLS_B_EN);
	osd_wr_en(OSD_CTRL_EN | OSD_RLS_EN);
}






void show_Video_3_page (void)
{
	osd_init();

	spi_load_rls(Video_3_com_1_rlsatt_ptr, Video_3_com_1_rlsatt_addr,
			Video_3_com_1_rlsatt_size, VIDEO_3_CODE_OFFSET);

	spi_load_rls(Video_3__dummy1__rlsatt_ptr, Video_3__dummy1__rlsatt_addr,
			Video_3__dummy1__rlsatt_size, VIDEO_3_CODE_OFFSET); // dummy


	spi_load_rls(Video_3_com_0_rlsatt_ptr, Video_3_com_0_rlsatt_addr,
			Video_3_com_0_rlsatt_size, VIDEO_3_CODE_OFFSET);

	spi_load_rls(Video_3__dummy2__rlsatt_ptr, Video_3__dummy2__rlsatt_addr,
			Video_3__dummy2__rlsatt_size, VIDEO_3_CODE_OFFSET); // dummy


	spi_load_rls(Video_3_com_2_rlsatt_ptr, Video_3_com_2_rlsatt_addr,
			Video_3_com_2_rlsatt_size, VIDEO_3_CODE_OFFSET);

	spi_load_rls(Video_3__dummy3__rlsatt_ptr, Video_3__dummy3__rlsatt_addr,
			Video_3__dummy3__rlsatt_size, VIDEO_3_CODE_OFFSET); // dummy




	row_A_disable();
	row_B_disable();
	row_C_disable();
	row_D_disable();
	rlg_A_disable();
	rlg_B_disable();
	rlg_C_disable();
	rlg_D_disable();
	rls_B_config(Video_3_RLs_Thread_B_regaddr);
	rls_C_config(Video_3_RLs_Thread_C_regaddr);
	rls_D_config(Video_3_RLs_Thread_D_regaddr);
	win_A_disable();
	win_B_disable();
	win_C_disable();
	win_D_disable();
	mat_A_disable();
	mat_B_disable();
	mat_C_disable();
	mat_D_disable();


	osd_wr_rls_en(RLS_D_EN | RLS_C_EN | RLS_B_EN);
	osd_wr_en(OSD_CTRL_EN | OSD_RLS_EN);
}






void show_Video_4_page (void)
{
	osd_init();

	spi_load_rls(Video_4_com_1_rlsatt_ptr, Video_4_com_1_rlsatt_addr,
			Video_4_com_1_rlsatt_size, VIDEO_4_CODE_OFFSET);

	spi_load_rls(Video_4__dummy1__rlsatt_ptr, Video_4__dummy1__rlsatt_addr,
			Video_4__dummy1__rlsatt_size, VIDEO_4_CODE_OFFSET); // dummy


	spi_load_rls(Video_4_com_0_rlsatt_ptr, Video_4_com_0_rlsatt_addr,
			Video_4_com_0_rlsatt_size, VIDEO_4_CODE_OFFSET);

	spi_load_rls(Video_4__dummy2__rlsatt_ptr, Video_4__dummy2__rlsatt_addr,
			Video_4__dummy2__rlsatt_size, VIDEO_4_CODE_OFFSET); // dummy


	spi_load_rls(Video_4_com_2_rlsatt_ptr, Video_4_com_2_rlsatt_addr,
			Video_4_com_2_rlsatt_size, VIDEO_4_CODE_OFFSET);

	spi_load_rls(Video_4__dummy3__rlsatt_ptr, Video_4__dummy3__rlsatt_addr,
			Video_4__dummy3__rlsatt_size, VIDEO_4_CODE_OFFSET); // dummy




	row_A_disable();
	row_B_disable();
	row_C_disable();
	row_D_disable();
	rlg_A_disable();
	rlg_B_disable();
	rlg_C_disable();
	rlg_D_disable();
	rls_B_config(Video_4_RLs_Thread_B_regaddr);
	rls_C_config(Video_4_RLs_Thread_C_regaddr);
	rls_D_config(Video_4_RLs_Thread_D_regaddr);
	win_A_disable();
	win_B_disable();
	win_C_disable();
	win_D_disable();
	mat_A_disable();
	mat_B_disable();
	mat_C_disable();
	mat_D_disable();


	osd_wr_rls_en(RLS_D_EN | RLS_C_EN | RLS_B_EN);
	osd_wr_en(OSD_CTRL_EN | OSD_RLS_EN);
}






void show_Video_5_page (void)
{
	osd_init();

	spi_load_rls(Video_5_com_1_rlsatt_ptr, Video_5_com_1_rlsatt_addr,
			Video_5_com_1_rlsatt_size, VIDEO_5_CODE_OFFSET);

	spi_load_rls(Video_5__dummy1__rlsatt_ptr, Video_5__dummy1__rlsatt_addr,
			Video_5__dummy1__rlsatt_size, VIDEO_5_CODE_OFFSET); // dummy


	spi_load_rls(Video_5_com_0_rlsatt_ptr, Video_5_com_0_rlsatt_addr,
			Video_5_com_0_rlsatt_size, VIDEO_5_CODE_OFFSET);

	spi_load_rls(Video_5__dummy2__rlsatt_ptr, Video_5__dummy2__rlsatt_addr,
			Video_5__dummy2__rlsatt_size, VIDEO_5_CODE_OFFSET); // dummy


	spi_load_rls(Video_5_com_2_rlsatt_ptr, Video_5_com_2_rlsatt_addr,
			Video_5_com_2_rlsatt_size, VIDEO_5_CODE_OFFSET);

	spi_load_rls(Video_5__dummy3__rlsatt_ptr, Video_5__dummy3__rlsatt_addr,
			Video_5__dummy3__rlsatt_size, VIDEO_5_CODE_OFFSET); // dummy




	row_A_disable();
	row_B_disable();
	row_C_disable();
	row_D_disable();
	rlg_A_disable();
	rlg_B_disable();
	rlg_C_disable();
	rlg_D_disable();
	rls_B_config(Video_5_RLs_Thread_B_regaddr);
	rls_C_config(Video_5_RLs_Thread_C_regaddr);
	rls_D_config(Video_5_RLs_Thread_D_regaddr);
	win_A_disable();
	win_B_disable();
	win_C_disable();
	win_D_disable();
	mat_A_disable();
	mat_B_disable();
	mat_C_disable();
	mat_D_disable();


	osd_wr_rls_en(RLS_D_EN | RLS_C_EN | RLS_B_EN);
	osd_wr_en(OSD_CTRL_EN | OSD_RLS_EN);
}






void show_Video_6_page (void)
{
	osd_init();

	spi_load_rls(Video_6_com_1_rlsatt_ptr, Video_6_com_1_rlsatt_addr,
			Video_6_com_1_rlsatt_size, VIDEO_6_CODE_OFFSET);

	spi_load_rls(Video_6__dummy1__rlsatt_ptr, Video_6__dummy1__rlsatt_addr,
			Video_6__dummy1__rlsatt_size, VIDEO_6_CODE_OFFSET); // dummy


	spi_load_rls(Video_6_com_2_rlsatt_ptr, Video_6_com_2_rlsatt_addr,
			Video_6_com_2_rlsatt_size, VIDEO_6_CODE_OFFSET);

	spi_load_rls(Video_6__dummy2__rlsatt_ptr, Video_6__dummy2__rlsatt_addr,
			Video_6__dummy2__rlsatt_size, VIDEO_6_CODE_OFFSET); // dummy


	spi_load_rls(Video_6_com_0_rlsatt_ptr, Video_6_com_0_rlsatt_addr,
			Video_6_com_0_rlsatt_size, VIDEO_6_CODE_OFFSET);

	spi_load_rls(Video_6__dummy3__rlsatt_ptr, Video_6__dummy3__rlsatt_addr,
			Video_6__dummy3__rlsatt_size, VIDEO_6_CODE_OFFSET); // dummy




	row_A_disable();
	row_B_disable();
	row_C_disable();
	row_D_disable();
	rlg_A_disable();
	rlg_B_disable();
	rlg_C_disable();
	rlg_D_disable();
	rls_B_config(Video_6_RLs_Thread_B_regaddr);
	rls_C_config(Video_6_RLs_Thread_C_regaddr);
	rls_D_config(Video_6_RLs_Thread_D_regaddr);
	win_A_disable();
	win_B_disable();
	win_C_disable();
	win_D_disable();
	mat_A_disable();
	mat_B_disable();
	mat_C_disable();
	mat_D_disable();


	osd_wr_rls_en(RLS_D_EN | RLS_C_EN | RLS_B_EN);
	osd_wr_en(OSD_CTRL_EN | OSD_RLS_EN);
}






void show_Video_7_page (void)
{
	osd_init();

	spi_load_rls(Video_7_com_2_rlsatt_ptr, Video_7_com_2_rlsatt_addr,
			Video_7_com_2_rlsatt_size, VIDEO_7_CODE_OFFSET);

	spi_load_rls(Video_7__dummy1__rlsatt_ptr, Video_7__dummy1__rlsatt_addr,
			Video_7__dummy1__rlsatt_size, VIDEO_7_CODE_OFFSET); // dummy


	spi_load_rls(Video_7_com_1_rlsatt_ptr, Video_7_com_1_rlsatt_addr,
			Video_7_com_1_rlsatt_size, VIDEO_7_CODE_OFFSET);

	spi_load_rls(Video_7__dummy2__rlsatt_ptr, Video_7__dummy2__rlsatt_addr,
			Video_7__dummy2__rlsatt_size, VIDEO_7_CODE_OFFSET); // dummy


	spi_load_rls(Video_7_com_0_rlsatt_ptr, Video_7_com_0_rlsatt_addr,
			Video_7_com_0_rlsatt_size, VIDEO_7_CODE_OFFSET);

	spi_load_rls(Video_7__dummy3__rlsatt_ptr, Video_7__dummy3__rlsatt_addr,
			Video_7__dummy3__rlsatt_size, VIDEO_7_CODE_OFFSET); // dummy




	row_A_disable();
	row_B_disable();
	row_C_disable();
	row_D_disable();
	rlg_A_disable();
	rlg_B_disable();
	rlg_C_disable();
	rlg_D_disable();
	rls_B_config(Video_7_RLs_Thread_B_regaddr);
	rls_C_config(Video_7_RLs_Thread_C_regaddr);
	rls_D_config(Video_7_RLs_Thread_D_regaddr);
	win_A_disable();
	win_B_disable();
	win_C_disable();
	win_D_disable();
	mat_A_disable();
	mat_B_disable();
	mat_C_disable();
	mat_D_disable();


	osd_wr_rls_en(RLS_D_EN | RLS_C_EN | RLS_B_EN);
	osd_wr_en(OSD_CTRL_EN | OSD_RLS_EN);
}






void show_Zoom_Main_page (void)
{
	osd_init();

	spi_load_rls(Zoom_Main_com_0_rlsatt_ptr, Zoom_Main_com_0_rlsatt_addr,
			Zoom_Main_com_0_rlsatt_size, ZOOM_MAIN_CODE_OFFSET);

	spi_load_rls(Zoom_Main__dummy2__rlsatt_ptr, Zoom_Main__dummy2__rlsatt_addr,
			Zoom_Main__dummy2__rlsatt_size, ZOOM_MAIN_CODE_OFFSET); // dummy


	spi_load_rls(Zoom_Main_com_1_rlsatt_ptr, Zoom_Main_com_1_rlsatt_addr,
			Zoom_Main_com_1_rlsatt_size, ZOOM_MAIN_CODE_OFFSET);

	spi_load_rls(Zoom_Main__dummy3__rlsatt_ptr, Zoom_Main__dummy3__rlsatt_addr,
			Zoom_Main__dummy3__rlsatt_size, ZOOM_MAIN_CODE_OFFSET); // dummy




	row_A_disable();
	row_B_disable();
	row_C_disable();
	row_D_disable();
	rlg_A_disable();
	rlg_B_disable();
	rlg_C_disable();
	rlg_D_disable();
	rls_C_config(Zoom_Main_RLs_Thread_C_regaddr);
	rls_D_config(Zoom_Main_RLs_Thread_D_regaddr);
	win_A_disable();
	win_B_disable();
	win_C_disable();
	win_D_disable();
	mat_A_disable();
	mat_B_disable();
	mat_C_disable();
	mat_D_disable();


	osd_wr_rls_en(RLS_D_EN | RLS_C_EN);
	osd_wr_en(OSD_CTRL_EN | OSD_RLS_EN);
}






void show_Zoom_1_page (void)
{
	osd_init();

	spi_load_rls(Zoom_1_com_2_rlsatt_ptr, Zoom_1_com_2_rlsatt_addr,
			Zoom_1_com_2_rlsatt_size, ZOOM_1_CODE_OFFSET);

	spi_load_rls(Zoom_1__dummy1__rlsatt_ptr, Zoom_1__dummy1__rlsatt_addr,
			Zoom_1__dummy1__rlsatt_size, ZOOM_1_CODE_OFFSET); // dummy


	spi_load_rls(Zoom_1_com_1_rlsatt_ptr, Zoom_1_com_1_rlsatt_addr,
			Zoom_1_com_1_rlsatt_size, ZOOM_1_CODE_OFFSET);

	spi_load_rls(Zoom_1__dummy2__rlsatt_ptr, Zoom_1__dummy2__rlsatt_addr,
			Zoom_1__dummy2__rlsatt_size, ZOOM_1_CODE_OFFSET); // dummy


	spi_load_rls(Zoom_1_com_0_rlsatt_ptr, Zoom_1_com_0_rlsatt_addr,
			Zoom_1_com_0_rlsatt_size, ZOOM_1_CODE_OFFSET);

	spi_load_rls(Zoom_1__dummy3__rlsatt_ptr, Zoom_1__dummy3__rlsatt_addr,
			Zoom_1__dummy3__rlsatt_size, ZOOM_1_CODE_OFFSET); // dummy




	row_A_disable();
	row_B_disable();
	row_C_disable();
	row_D_disable();
	rlg_A_disable();
	rlg_B_disable();
	rlg_C_disable();
	rlg_D_disable();
	rls_B_config(Zoom_1_RLs_Thread_B_regaddr);
	rls_C_config(Zoom_1_RLs_Thread_C_regaddr);
	rls_D_config(Zoom_1_RLs_Thread_D_regaddr);
	win_A_disable();
	win_B_disable();
	win_C_disable();
	win_D_disable();
	mat_A_disable();
	mat_B_disable();
	mat_C_disable();
	mat_D_disable();


	osd_wr_rls_en(RLS_D_EN | RLS_C_EN | RLS_B_EN);
	osd_wr_en(OSD_CTRL_EN | OSD_RLS_EN);
}






void show_Zoom_2_page (void)
{
	osd_init();

	spi_load_rls(Zoom_2_com_2_rlsatt_ptr, Zoom_2_com_2_rlsatt_addr,
			Zoom_2_com_2_rlsatt_size, ZOOM_2_CODE_OFFSET);

	spi_load_rls(Zoom_2__dummy1__rlsatt_ptr, Zoom_2__dummy1__rlsatt_addr,
			Zoom_2__dummy1__rlsatt_size, ZOOM_2_CODE_OFFSET); // dummy


	spi_load_rls(Zoom_2_com_1_rlsatt_ptr, Zoom_2_com_1_rlsatt_addr,
			Zoom_2_com_1_rlsatt_size, ZOOM_2_CODE_OFFSET);

	spi_load_rls(Zoom_2__dummy2__rlsatt_ptr, Zoom_2__dummy2__rlsatt_addr,
			Zoom_2__dummy2__rlsatt_size, ZOOM_2_CODE_OFFSET); // dummy


	spi_load_rls(Zoom_2_com_0_rlsatt_ptr, Zoom_2_com_0_rlsatt_addr,
			Zoom_2_com_0_rlsatt_size, ZOOM_2_CODE_OFFSET);

	spi_load_rls(Zoom_2__dummy3__rlsatt_ptr, Zoom_2__dummy3__rlsatt_addr,
			Zoom_2__dummy3__rlsatt_size, ZOOM_2_CODE_OFFSET); // dummy




	row_A_disable();
	row_B_disable();
	row_C_disable();
	row_D_disable();
	rlg_A_disable();
	rlg_B_disable();
	rlg_C_disable();
	rlg_D_disable();
	rls_B_config(Zoom_2_RLs_Thread_B_regaddr);
	rls_C_config(Zoom_2_RLs_Thread_C_regaddr);
	rls_D_config(Zoom_2_RLs_Thread_D_regaddr);
	win_A_disable();
	win_B_disable();
	win_C_disable();
	win_D_disable();
	mat_A_disable();
	mat_B_disable();
	mat_C_disable();
	mat_D_disable();


	osd_wr_rls_en(RLS_D_EN | RLS_C_EN | RLS_B_EN);
	osd_wr_en(OSD_CTRL_EN | OSD_RLS_EN);
}






void show_Zoom_3_page (void)
{
	osd_init();

	spi_load_rls(Zoom_3_com_2_rlsatt_ptr, Zoom_3_com_2_rlsatt_addr,
			Zoom_3_com_2_rlsatt_size, ZOOM_3_CODE_OFFSET);

	spi_load_rls(Zoom_3__dummy1__rlsatt_ptr, Zoom_3__dummy1__rlsatt_addr,
			Zoom_3__dummy1__rlsatt_size, ZOOM_3_CODE_OFFSET); // dummy


	spi_load_rls(Zoom_3_com_0_rlsatt_ptr, Zoom_3_com_0_rlsatt_addr,
			Zoom_3_com_0_rlsatt_size, ZOOM_3_CODE_OFFSET);

	spi_load_rls(Zoom_3__dummy2__rlsatt_ptr, Zoom_3__dummy2__rlsatt_addr,
			Zoom_3__dummy2__rlsatt_size, ZOOM_3_CODE_OFFSET); // dummy


	spi_load_rls(Zoom_3_com_1_rlsatt_ptr, Zoom_3_com_1_rlsatt_addr,
			Zoom_3_com_1_rlsatt_size, ZOOM_3_CODE_OFFSET);

	spi_load_rls(Zoom_3__dummy3__rlsatt_ptr, Zoom_3__dummy3__rlsatt_addr,
			Zoom_3__dummy3__rlsatt_size, ZOOM_3_CODE_OFFSET); // dummy




	row_A_disable();
	row_B_disable();
	row_C_disable();
	row_D_disable();
	rlg_A_disable();
	rlg_B_disable();
	rlg_C_disable();
	rlg_D_disable();
	rls_B_config(Zoom_3_RLs_Thread_B_regaddr);
	rls_C_config(Zoom_3_RLs_Thread_C_regaddr);
	rls_D_config(Zoom_3_RLs_Thread_D_regaddr);
	win_A_disable();
	win_B_disable();
	win_C_disable();
	win_D_disable();
	mat_A_disable();
	mat_B_disable();
	mat_C_disable();
	mat_D_disable();


	osd_wr_rls_en(RLS_D_EN | RLS_C_EN | RLS_B_EN);
	osd_wr_en(OSD_CTRL_EN | OSD_RLS_EN);
}

